//
//  YBEarnDetailHeader.m
//  Nectar
//
//  Created by famer on 2023/11/10.
//  Copyright © 2023 asance. All rights reserved.
//

#import "YBEarnDetailHeader.h"

@implementation YBEarnDetailHeader


- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self){
        
        [self addSubview:self.titleLabel];
        [self addSubview:self.valueLabel];
        [self addSubview:self.extImageView];
        [self addSubview:self.lineView];
        [self addSubview:self.actionButton];
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    CGFloat width = self.frame.size.width;
    CGFloat leftMargin = 12;
    CGFloat topMargin = 16;
    
    ///
    CGSize titleLabelSize = [self.titleLabel textBoundingSizeWithMaxSize:CGSizeMake(width, 500)];
    self.titleLabel.frame = CGRectMake(0,
                                       0,
                                       width,
                                       titleLabelSize.height);
    
    self.titleLabel.centerY = self.height*0.5-titleLabelSize.height*0.5-5;
    
    CGSize valueLabelSize = [self.valueLabel textBoundingSizeWithMaxSize:CGSizeMake(width, 500)];
    self.valueLabel.frame = CGRectMake(0,
                                       0,
                                       width,
                                       valueLabelSize.height);
    self.valueLabel.centerY = self.height*0.5+titleLabelSize.height*0.5+5;
    
    self.extImageView.frame = CGRectMake(width-14, 0, 14, 14);
    self.extImageView.centerY = self.titleLabel.centerY;
    
    self.lineView.frame = CGRectMake(0, self.height-1, width, 1);
    
    self.actionButton.frame = self.bounds;
}

#pragma mark - Private Method
- (void)toExtAction{
    if(self.actionBlock){
        self.actionBlock();
    }
}

#pragma mark - Getter Setter

YBViewGetter(lineView, _lineView, [UIColor hexColor:@"F6F5F6"]);
YBLabelGetter(titleLabel, _titleLabel, [UIFont systemFontOfSize:12], @"Total Earn", [UIColor hexColor:@"84828C"], NSTextAlignmentCenter);
YBLabelGetter(valueLabel, _valueLabel, [UIFont boldSystemFontOfSize:16], @"* USDT", kThemeBlackColor, NSTextAlignmentCenter);

YBImageViewGetter(extImageView, _extImageView, [UIImage imageNamed:@"icon_nav_right"]);

- (UIButton *)actionButton{
    if(!_actionButton){
        _actionButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _actionButton.backgroundColor = kClearColor;
        [_actionButton setTitle:@"" forState:UIControlStateNormal];
        [_actionButton setTitle:@"" forState:UIControlStateSelected];
        [_actionButton setTitleColor:kClearColor forState:UIControlStateNormal];
        [_actionButton setTitleColor:kClearColor forState:UIControlStateSelected];
        [_actionButton addTarget:self action:@selector(toExtAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return  _actionButton;
}
@end
